/**
 * @author zhouheng
 * @date 2022年03月08日 18:56
 */

package com.atguigu.gulimall.product.config;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyThreadConfig {
    public static int coreThreadNum = Runtime.getRuntime().availableProcessors();

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(
            coreThreadNum,
            coreThreadNum * 2,
            10,
            TimeUnit.SECONDS,
            new LinkedBlockingDeque<>(1000),
            Executors.defaultThreadFactory());
    }
}
